package com.enhe.gck.fg;

import cn.hutool.core.util.StrUtil;
import com.enhe.gck.com.oracle.OracleController;
import com.enhe.gck.com.oracle.OracleEntity;
import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.communal.PublicReturn;
import com.enhe.gck.pojo.OperationCommand;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.FGRelationCorrelation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.fg.FuncGroupContext;
import com.kuangkie.carbon.fg.ImproveResultFactory;
import com.kuangkie.carbon.fg.SecondRoundImproveFuncGroup;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.CarbonRelationType; //关系类型Code
import com.enhe.gck.item.OperationCommandHWANE18935Item; // 模型属性Code

import javax.annotation.Resource;

@Slf4j
@Repository(value = "hwane18935366042330866425862")
public class OperationCommandHWANE18935BNB implements SecondRoundImproveFuncGroup{
	@Resource
	private OracleController oracleController;
	
	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
		OperationCommand info=proRecord.getBean(OperationCommand.class);

		if(!verify(info)){
			PublicMethod.returnMessage(improveResultFactory, PublicReturn.ORDER_10);
		}

		if(proRecord.isNew()){
			if(String.valueOf(CarbonEnumKeyValue.操作按钮_经销商同步_jxstb).equals(info.getType())){
				log.info("经销商同步");
				OracleEntity.Parameter data=new OracleEntity.Parameter();
				if(!oracleController.getyCompan(data)){
					PublicMethod.returnMessage(improveResultFactory, PublicReturn.SYSTEM_2);
					return ;
				}
			}

			if(String.valueOf(CarbonEnumKeyValue.操作按钮_供货商同步_ghstb).equals(info.getType())){
				log.info("供货商同步");
				OracleEntity.Parameter data=new OracleEntity.Parameter();
				if(!oracleController.getSupplier(data)){
					PublicMethod.returnMessage(improveResultFactory, PublicReturn.SYSTEM_2);
					return ;
				}
			}

			if(String.valueOf(CarbonEnumKeyValue.操作按钮_物料同步_wltb).equals(info.getType())){
				log.info("物料同步");
				OracleEntity.Parameter data=new OracleEntity.Parameter();
				if(!oracleController.geMaterial(data)){
					PublicMethod.returnMessage(improveResultFactory, PublicReturn.SYSTEM_2);
					return ;
				}
			}
		}
	}

	private boolean verify(OperationCommand info){
		if(StrUtil.isBlank(info.getType())){
			return false;
		}
		return true;
	}
}
